package com.kdtech.crawler;

import org.jsoup.nodes.Document;

import com.kd.crawler.common.utils.HttpClientUtils;
import com.kd.crawler.http.HttpResponse;
import com.kd.crawler.parser.url.UrlParser;
import com.kdtech.entity.crawler.UrlMeta;

public class CrawlHTML {

	public static UrlMeta responseToURL(String url) {
		HttpResponse response = HttpClientUtils.httpGetRequest(url);
		if(null == response) {
			return null;
		}
		UrlMeta meta = new UrlMeta();
		meta.setUrl(url);
		meta.setHtml(response.getHtml());
		meta.setStatusCode(response.getStatus());
		meta.setRespondTimes(response.getCrawlTime());
		return meta;
	}
	
	public static String GetHtml(String url) {
		HttpResponse response = HttpClientUtils.httpGetRequest(url);
		if(null == response) {
			return null;
		}
		return response.getHtml();
	}
	
	public static HttpResponse get(String url){
		try{
			HttpResponse httpResponse= HttpClientUtils.httpGetRequest(url);
			return httpResponse;
		}catch(Exception e){
			return new HttpResponse(1000,null,null);
		}
	}
	
	public static String GetHtml(String url, String encode) {
		return GetHtml(url);
	}
	
	public static String complementURL(String url, String baseUrl, Document doc, boolean flag) {
		return UrlParser.completeURL(url, baseUrl);
	}
	
	
	public static String getHtml(String url, String encode, String s) {
		return GetHtml(url);
	}
}
